using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Spike.ContractBuilder;

namespace Spike.TestHarness.Host
{
    public partial class ManageHosts : Form
    {
        public ManageHosts()
        {
            InitializeComponent();
        }

        public void RefreshHosts()
        {
            foreach (TabPage page in tabHosts.TabPages)
            {
                HostControl cntrl = (HostControl)page.Controls[0];
                cntrl.ClearEndpointControls();
                cntrl.Dispose();
                page.Dispose();
            }

            ContractGenerator.Instance.LoadHosts();

            foreach (string contract in ContractGenerator.Instance.Hosts.Keys)
            {
                TabPage page = new TabPage(contract);                
                HostControl host = new HostControl();
                host.Dock = DockStyle.Fill;
                host.ServiceHostContract = contract;
                page.Controls.Add(host);                
                tabHosts.TabPages.Add(page);
            }
        }

        private void addServiceContractToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddHostDialog dlg = new AddHostDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                RefreshHosts();
            }
            dlg.Dispose();
        }

        private void lstHosts_SelectedIndexChanged(object sender, EventArgs e)
        {




        }

    }
}